package com.adgox.tiantianbiting.adapter;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.adgox.tiantianbiting.R;
import com.adgox.tiantianbiting.bean.SignDayBean;
import com.adgox.tiantianbiting.bean.SignWeekBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by tang on 2019/3/4.
 */

public class SignAdapter extends RecyclerView.Adapter<SignAdapter.ViewHolder> {

    private List<SignWeekBean> datas;

    public SignAdapter(List<SignWeekBean> datas) {
        this.datas = datas;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_sign_rv_item, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        SignWeekBean signWeekBean = datas.get(position);
        holder.iconCheckBlue.setImageResource(signWeekBean.getSignStatus()==0?R.drawable.img_sign_blue_uncheck:R.drawable.img_sign_blue_check);
        holder.tvWeek.setText("第"+(position+1)+"周");
        switch (signWeekBean.getSignStatus()){
            case 0:
                holder.tvTips.setText("未解锁");
                break;
            case 1:
                holder.tvTips.setText("已签到");
                break;
            case 2:
                holder.tvTips.setText("正在签到");
                break;
            case 3:
                holder.tvTips.setText("待签到");
        }

        ArrayList<TextView> reds = new ArrayList<>();
        ArrayList<TextView> days = new ArrayList<>();
        reds.add(holder.tvRed1);
        reds.add(holder.tvRed2);
        reds.add(holder.tvRed3);
        reds.add(holder.tvRed4);
        reds.add(holder.tvRed5);
        reds.add(holder.tvRed6);
        reds.add(holder.tvRed7);
        days.add(holder.tvDay1);
        days.add(holder.tvDay2);
        days.add(holder.tvDay3);
        days.add(holder.tvDay4);
        days.add(holder.tvDay5);
        days.add(holder.tvDay6);
        days.add(holder.tvDay7);

        List<SignDayBean> subSignInBo = signWeekBean.getSubSignInBo();

        for (int i = 0; i < subSignInBo.size() ; i++){
            SignDayBean dayBean = subSignInBo.get(i);
            reds.get(i).setBackgroundResource(dayBean.getSignStatus()==1?R.drawable.bg_sign_red_check: R.drawable.bg_sign_red_uncheck);
            reds.get(i).setTextColor(dayBean.getSignStatus()==1?Color.parseColor("#ffffff"):Color.parseColor("#f59595"));
            days.get(i).setTextColor(dayBean.getSignStatus()==1?Color.parseColor("#cc1f00"):Color.parseColor("#b0b0b0"));
        }
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.icon_check_blue)
        ImageView iconCheckBlue;
        @BindView(R.id.tv_week)
        TextView tvWeek;
        @BindView(R.id.tv_tips)
        TextView tvTips;
        @BindView(R.id.tv_red1)
        TextView tvRed1;
        @BindView(R.id.tv_day1)
        TextView tvDay1;
        @BindView(R.id.tv_red2)
        TextView tvRed2;
        @BindView(R.id.tv_day2)
        TextView tvDay2;
        @BindView(R.id.tv_red3)
        TextView tvRed3;
        @BindView(R.id.tv_day3)
        TextView tvDay3;
        @BindView(R.id.tv_red4)
        TextView tvRed4;
        @BindView(R.id.tv_day4)
        TextView tvDay4;
        @BindView(R.id.tv_red5)
        TextView tvRed5;
        @BindView(R.id.tv_day5)
        TextView tvDay5;
        @BindView(R.id.tv_red6)
        TextView tvRed6;
        @BindView(R.id.tv_day6)
        TextView tvDay6;
        @BindView(R.id.tv_red7)
        TextView tvRed7;
        @BindView(R.id.tv_day7)
        TextView tvDay7;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
